找传奇、传世资源到传世资源站!

android_自定义Spinner源码实现_

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

android_自定义Spinner源码实现_ Android平台开发-第1张android_自定义Spinner源码实现_ Android平台开发-第2张

public class MainActivity extends Activity implements OnClickListener {
	private String state = "China";
	private TextView edit_state;

	String[] country;
	private SpinerPopWindow SpinerCountry = null;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		// 每次创建一个新的Activity都需要把它放到activity链表管理里面,以便释放内存
		init();
	}

	public void init() {
		edit_state = (TextView) findViewById(R.id.edit_state);
		edit_state.setText(state);
		setupCountry();
	}

	private void setupCountry() {
		edit_state.setOnClickListener(this);
		country = getResources().getStringArray(R.array.spinner_country);
		SpinerCountry = new SpinerPopWindow(this);
		SpinerCountry.setSpinnerAdatper(country);
		SpinerCountry.setItemListener(new IOnItemSelectListener() {
			@Override
			public void onItemClick(int pos) {
				// TODO Auto-generated method stub
				setCountry(pos);
			}
		});

	}

	@Override
	public void onClick(View view) {
		switch (view.getId()) {
		// case R.id.spinner_state_sex:
		// showSpinWindow();
		// break;
		case R.id.edit_state:
			showCountry();
			break;

		}
	}

	private void setCountry(int pos) {
		if (pos >= 0 && pos <= country.length) {
			// CustemObject value = nameList.get(pos);
			edit_state.setText(country[pos]);
			state = country[pos];
		}
	}

	private void showCountry() {
		// Log.e("", "showSpinWindow");
		SpinerCountry.setWidth(edit_state.getWidth());
		SpinerCountry.showAsDropDown(edit_state);
	}
}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复